package com.jingdianjichi.auth.domain.service.impl;

import cn.dev33.satoken.stp.SaTokenInfo;
import com.jingdianjichi.auth.common.enums.IsDeleteFlagEnum;
import com.jingdianjichi.auth.domain.convert.AuthRoleConvert;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.entity.AuthUserBO;
import com.jingdianjichi.auth.domain.redis.RedisUtil;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.infra.basic.entity.AuthRole;
import com.jingdianjichi.auth.infra.basic.entity.AuthUser;
import com.jingdianjichi.auth.infra.basic.mapper.AuthRoleDao;
import com.jingdianjichi.auth.infra.basic.service.AuthRoleService;
import com.jingdianjichi.auth.infra.basic.service.AuthUserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 角色表(AuthRole)表服务实现类
 *
 * @author makejava
 * @since 2025-02-21 15:12:58
 */
@Service
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource
    private AuthRoleService authRoleService;
    private RedisUtil   redisUtil;
    private static final  String LOGIN_PREFIX = "loginCode";
    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public AuthRole queryById(Long id) {
        return null;
    }

    /**
     * 新增数据
     *
     * @param authRole 实例对象
     * @return 实例对象
     */
    @Override
    public AuthRole insert(AuthRole authRole) {
        return null;
    }

    /**
     * 修改数据
     *
     * @param authRole 实例对象
     * @return 实例对象
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        AuthRole authRole = AuthRoleConvert.INSTANCE.AuthRoleBoToEntity(authRoleBO);
        authRole.setIsDeleted(IsDeleteFlagEnum.UN_DELETED.getCode());
        int count=authRoleService.add(authRole);
        //redis
        return count > 0;

    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return true;
    }

    /**
     * 更新角色信息
     * @param authUserBO
     * @return
     */
    @Override
    public Boolean update(AuthRoleBO authUserBO) {
        AuthRole authRole = AuthRoleConvert.INSTANCE.AuthRoleBoToEntity(authUserBO);
        Integer count = authRoleService.update(authRole);
            //redis
        return count > 0;
    }

    @Override
    public Boolean delete(AuthRoleBO authUserBO) {
        AuthRole authRole = new AuthRole();
        authRole.setId(authUserBO.getId());
        authRole.setIsDeleted(IsDeleteFlagEnum.DELETED.getCode());
        int count=authRoleService.update(authRole);
        return count > 0;
    }

    /**
     * 登录校验
     * @param validCode
     * @return
     */

}
